<#include "/macro.include"/> 
<#include "/custom.include"/> 
<#assign className = table.className>
<#assign classNameLower = className?lower_case>

var init${className}Bean;
var get${className}BeanFromOpenPage = function(){
	var ${classNameLower}Bean = {};
	<#list table.columns as column>
	${classNameLower}Bean.${column.columnNameLower} = jQuery('#${column.columnNameLower}Editor').val();
	<#if !column.htmlHidden>
	<#if !column.nullable>
	if(!${classNameLower}Bean.${column.columnNameLower}){
		$.ligerDialog.error("请输入${column.columnAlias}!");
		return null;
	}<#if column.isDateTimeColumn>else{
		${classNameLower}Bean.${column.columnNameLower} = new Date(Date.parse((${classNameLower}Bean.${column.columnNameLower}+':00').replace(/-/g,   "/")));
	}
	</#if>
	</#if>
	<#else>
	
	<#if column.isDateTimeColumn>
	if(${classNameLower}Bean.${column.columnNameLower}){
		${classNameLower}Bean.${column.columnNameLower} = new Date(Date.parse((${classNameLower}Bean.${column.columnNameLower}+':00').replace(/-/g,   "/")));
	}else{
		${classNameLower}Bean.${column.columnNameLower} = ${classNameLower}Bean.${column.columnNameLower}
	}
	</#if>
	</#if>
	</#list>
	
	return ${classNameLower}Bean;
};

var init${className}Page = function(){
	<#list table.columns as column>
	
	<#if !column.htmlHidden>
	<#if column.isDateTimeColumn>
	jQuery("#${column.columnNameLower}Editor").ligerDateEditor({
		format:'yyyy-MM-dd hh:mm:ss',
		showTime:true,
	});
	</#if>
	</#if>
	</#list>
};

var bind${className}UpdateButtom = function(){
	jQuery('#updateEdit').unbind('click').click(function(){
		var ${classNameLower}Bean = get${className}BeanFromOpenPage();
		if(null != ${classNameLower}Bean){
			doSave${className}s([${classNameLower}Bean]);
		}
	});
};
var bind${className}ResetButtom = function(){
	jQuery('#resetEdit').unbind('click').click(function(){
		if(!init${className}Bean){
			<#list table.columns as column>
			<#if !column.htmlHidden>
			jQuery("#${column.columnNameLower}Editor").val('');
			</#if>
			</#list>
		}else{
			<#list table.columns as column>
			<#if !column.htmlHidden>
			if(!init${className}Bean.${column.columnNameLower}){
				jQuery("#${column.columnNameLower}Editor").val('');
			}else{
				<#if column.isDateTimeColumn>
				var temp = new Date(init${className}Bean.${column.columnNameLower});
				jQuery("#${column.columnNameLower}Editor").val(temp.formatLiger());
				<#else>
				jQuery("#${column.columnNameLower}Editor").val(init${className}Bean.${column.columnNameLower});
				</#if>
			}
			</#if>
			</#list>
		}
	});
};



jQuery(function(){
	init${className}Page();
	bind${className}UpdateButtom();
	bind${className}ResetButtom();
});